package com.czl.module_service.view.approvalFlow

import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.data.bean.tengyun.TaskUserBean
import com.czl.module_service.R
import com.czl.module_service.databinding.ItemApprovalFlowBinding
import com.czl.module_service.databinding.ItemChildApprovalFlowBinding

/**
 * @author by xubin
 * PS: Not easy to write code, please indicate.
 */
class ApprovalFlowAdapter :
    BaseQuickAdapter<TaskUserBean, BaseDataBindingHolder<ItemApprovalFlowBinding>>(R.layout.item_approval_flow) {
    override fun convert(
        holder: BaseDataBindingHolder<ItemApprovalFlowBinding>,
        item: TaskUserBean
    ) {
        holder.dataBinding?.run {
            data = item
            hiddenLine = holder.layoutPosition == 0
            hiddenAdd = item.taskUserList == null || item.taskUserList!!.isEmpty()
            executePendingBindings()
        }
        if (item.taskUserList != null && item.taskUserList!!.isNotEmpty()) {
            holder.dataBinding?.childRecyclerView?.visibility = View.VISIBLE
            val childAdapter = ChildApprovalFlowAdapter(item.taskUserList!!)
            holder.dataBinding?.childRecyclerView?.run {
                layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
                adapter = childAdapter
            }
        }
    }
}

class ChildApprovalFlowAdapter(list: MutableList<TaskUserBean>) :
    BaseQuickAdapter<TaskUserBean, BaseDataBindingHolder<ItemChildApprovalFlowBinding>>(
        R.layout.item_child_approval_flow,
        list
    ) {
    override fun convert(
        holder: BaseDataBindingHolder<ItemChildApprovalFlowBinding>,
        item: TaskUserBean
    ) {
        holder.dataBinding?.run {
            data = item
            hiddenAdd = holder.layoutPosition == 0
            executePendingBindings()
        }
    }

}